<?php declare(strict_types=1);


namespace App\Services\Pay\GuoTonXinYi;

use App\Exceptions\BizException;
use App\Services\Pay\ResultVo;
use Illuminate\Support\Facades\Log;

class  BaseInfo
{

    public static function addCustQueryFallAgetId(array $params, array $config): ResultVo
    {

    }


    public static function addCustRelatedBanksQuery(array $params, array $config): ResultVo
    {

    }


    public static function orderAgetInfoQuery(array $params, array $config): ResultVo
    {

    }

    public static function addCustQueryInfoByCard(array $params, array $config): ResultVo
    {

    }


    public static function queryInfoByCard(string $cardNo, array $config): ResultVo
    {
        try {
            if (empty($cardNo)) {
                throw new BizException("银行卡账号不能为空");
            }
            $url = Config::getDomain() . Config::addCustQueryInfoByCard;
            $reqData = [
                "agetId" => $config["agetId"],
                "cardNo" => $cardNo,
                "version" => Config::VERSION,
            ];
            $sign = Config::getSign($reqData, $config["public_key"]);
            $reqData["sign"] = $sign;
            $resultArray = Config::get($url, $reqData);
            Log::channel("income")->info("queryInfoByCard", [
                "url" => $url,
                "reqData" => $reqData,
                "resData" => $resultArray
            ]);
            if ($resultArray["code"] != "000000") {
                throw new BizException($resultArray["msg"]);
            }
            $resultVo = ResultVo::code("ok")::data($resultArray["data"])::msg($resultArray["msg"]);
        } catch (\Exception $e) {
            $resultVo = ResultVo::code("failed")::data(null)::msg($e->getMessage() . "File:" . $e->getFile() . "Line:" . $e->getLine());
        }
        return $resultVo;
    }

    public static function addCustGetTopMcc(array $params, array $config): ResultVo
    {
        try {
            $url = Config::getDomain() . Config::addCustGetTopMcc;
            $reqData = [
                "agetId" => $config["agetId"],
                "type" => (string)$params["type"],
                "version" => Config::VERSION,
            ];
            $sign = Config::getSign($reqData, $config["public_key"]);
            $reqData["sign"] = $sign;
            $resultArray = Config::get($url, $reqData);
            Log::channel("income")->info("addCustGetTopMcc", [
                "url" => $url,
                "reqData" => $reqData,
                "resData" => $resultArray
            ]);
            if ($resultArray["code"] != "000000") {
                throw new BizException($resultArray["msg"]);
            }
            $resultVo = ResultVo::code("ok")::data($resultArray["data"])::msg($resultArray["msg"]);
        } catch (\Exception $e) {
            $resultVo = ResultVo::code("failed")::data(null)::msg($e->getMessage() . "File:" . $e->getFile() . "Line:" . $e->getLine());
        }
        return $resultVo;
    }

    public static function addCustGetSecondMcc(array $params, array $config): ResultVo
    {
        try {
            $url = Config::getDomain() . Config::addCustGetSecondMcc;
            $reqData = [
                "agetId" => $config["agetId"],
                "busMccId" => $params["busMccId"],
                "version" => Config::VERSION
            ];
            $sign = Config::getSign($reqData, $config["public_key"]);
            $reqData["sign"] = $sign;
            $resultArray = Config::get($url, $reqData);
            Log::channel("income")->info("addCustGetSecondMcc", [
                "url" => $url,
                "reqData" => $reqData,
                "resData" => $resultArray
            ]);
            if ($resultArray["code"] != "000000") {
                throw new BizException($resultArray["msg"]);
            }
            $resultVo = ResultVo::code("ok")::data($resultArray["data"])::msg($resultArray["msg"]);
        } catch (\Exception $e) {
            $resultVo = ResultVo::code("failed")::data(null)::msg($e->getMessage() . "File:" . $e->getFile() . "Line:" . $e->getLine());
        }
        return $resultVo;
    }

    public static function addCustGetPublicProvince(array $params, array $config): ResultVo
    {
        try {
            $url = Config::getDomain() . Config::getPublicProvince;
            $reqData = [
                "agetId" => $config["agetId"],
                "version" => Config::VERSION
            ];
            $sign = Config::getSign($reqData, $config["public_key"]);
            $reqData["sign"] = $sign;
            $resultArray = Config::get($url, $reqData);
            $resultVo = ResultVo::code("ok")::data($resultArray["data"])::msg($resultArray["msg"]);
        } catch (\Exception $e) {
            $resultVo = ResultVo::code("failed")::data(null)::msg($e->getMessage() . "File:" . $e->getFile() . "Line:" . $e->getLine());
        }
        return $resultVo;
    }

    public static function addCustGetPublicCity(array $params, array $config): ResultVo
    {
        try {
            $url = Config::getDomain() . Config::getPublicCity;
            $reqData = [
                "agetId" => $config["agetId"],
                "code" => $params["code"],
                "version" => Config::VERSION
            ];
            $sign = Config::getSign($reqData, $config["public_key"]);
            $reqData["sign"] = $sign;
            $resultArray = Config::get($url, $reqData);
            $resultVo = ResultVo::code("ok")::data($resultArray["data"])::msg($resultArray["msg"]);
        } catch (\Exception $e) {
            $resultVo = ResultVo::code("failed")::data(null)::msg($e->getMessage() . "File:" . $e->getFile() . "Line:" . $e->getLine());
        }
        return $resultVo;
    }


    public static function addCustGetProvince(array $params, array $config): ResultVo
    {
        try {
            $url = Config::getDomain() . Config::addCustGetProvince;
            $reqData = [
                "agetId" => $config["agetId"],
                "version" => Config::VERSION
            ];
            $sign = Config::getSign($reqData, $config["public_key"]);
            $reqData["sign"] = $sign;
            $resultArray = Config::get($url, $reqData);
            if ($resultArray["code"] != "000000") {
                throw new BizException($resultArray["msg"]);
            }
            $resultVo = ResultVo::code("ok")::data($resultArray["data"])::msg($resultArray["msg"]);
        } catch (\Exception $e) {
            $resultVo = ResultVo::code("failed")::data(null)::msg($e->getMessage() . "File:" . $e->getFile() . "Line:" . $e->getLine());
        }
        return $resultVo;
    }


    public static function addCustGetCity(array $params, array $config): ResultVo
    {
        try {
            $url = Config::getDomain() . Config::addCustGetCity;
            $reqData = [
                "agetId" => $config["agetId"],
                "code" => $params["code"],
                "version" => Config::VERSION
            ];
            $sign = Config::getSign($reqData, $config["public_key"]);
            $reqData["sign"] = $sign;
            $resultArray = Config::get($url, $reqData);
            if ($resultArray["code"] != "000000") {
                throw new BizException($resultArray["msg"]);
            }
            $resultVo = ResultVo::code("ok")::data($resultArray["data"])::msg($resultArray["msg"]);
        } catch (\Exception $e) {
            $resultVo = ResultVo::code("failed")::data(null)::msg($e->getMessage() . "File:" . $e->getFile() . "Line:" . $e->getLine());
        }
        return $resultVo;
    }

    public static function addCustGetBranchInfo(array $params, array $config): ResultVo
    {
        try {
            $url = Config::getDomain() . Config::addCustGetBranchInfo;
            $reqData = [
                "agetId" => $config["orgId"],
                "bankCode" => $params["bankCode"],
                "code" => $params["code"],
                "version" => Config::VERSION
            ];
            $sign = Config::getSign($reqData, $config["public_key"]);
            $reqDate["sign"] = $sign;
            $resultArray = Config::post($url, $reqDate);
            $resultVo = ResultVo::code("ok")::data($resultArray["data"])::msg($resultArray["msg"]);
        } catch (\Exception $e) {
            $resultVo = ResultVo::code("error")::data(null)::msg($e->getMessage() . "File:" . $e->getFile() . "Line:" . $e->getLine());
        }
        return $resultVo;
    }


    public static function addCustGetBankInfo(array $params, array $config): ResultVo
    {
        try {
            $url = Config::getDomain() . Config::addCustGetBankInfo;
            $reqData = [
                "agetId" => $config["orgId"],
                "version" => Config::VERSION
            ];
            $sign = Config::getSign($reqData, $config["public_key"]);
            $reqDate["sign"] = $sign;
            $resultArray = Config::post($url, $reqDate);
            $resultVo = ResultVo::code("ok")::data($resultArray["data"])::msg($resultArray["msg"]);
        } catch (\Exception $e) {
            $resultVo = ResultVo::code("error")::data(null)::msg($e->getMessage() . "File:" . $e->getFile() . "Line:" . $e->getLine());
        }
        return $resultVo;
    }


    public static function addCustGetArea(array $params, array $config): ResultVo
    {
        try {
            $url = Config::getDomain() . Config::addCustGetArea;
            $reqData = [
                "agetId" => $config["agetId"],
                "code" => $params["code"],
                "version" => Config::VERSION
            ];
            $sign = Config::getSign($reqData, $config["public_key"]);
            $reqData["sign"] = $sign;
            $resultArray = Config::get($url, $reqData);
            if ($resultArray["code"] != "000000") {
                throw new BizException($resultArray["msg"]);
            }
            $resultVo = ResultVo::code("ok")::data($resultArray["data"])::msg($resultArray["msg"]);
        } catch (\Exception $e) {
            $resultVo = ResultVo::code("failed")::data(null)::msg($e->getMessage() . "File:" . $e->getFile() . "Line:" . $e->getLine());
        }
        return $resultVo;
    }
}